#include "trap.h"
   .set mips32
   .set noat
   .globl main
   .text
main:

#################################
# $v0 = 0xfffffffe
# $v1 = 0x80000000
# $a0 = 0x000f100e
# $a1 = 0x00020077
# $a2 = 0x00100000
# $a3 = 0xffffffff
# $t0 = 0x00020077
# $t1 = 0x00100000
# $t2 = 0xffffffff
# $t3 = 0xfffffffe
# $t4 = 0x7fffffff
# $t5 = 0x80000000
# $t6 = 0x7fffffff
# $t7 = 0x00011085
# $t8 = 0x000f0000
# $t9 = 0xfffff0f0
# $gp = 0x00011085
# $sp = 0x000f0000
# $fp = 0xfffff0f0
# $s7 = 0x000f100e
#################################

# ADD
    # 一般情况 正+正
    li $s0, 0x10086                 
    li $s1, 0x0000fff1                 
    add $t0, $s0, $s1            # $t0 = 0x00020077

    # 0x000f000f+0x0000fff1=0x00100000 进位
    li $s2, 0x000f000f                      
    add $t1, $s1, $s2            # $t1 = 0x00100000

    # 0x0000ffff+0xffff0000=0xffffffff 正+负
    li $s3, 0x0000ffff           
    li $s4, 0xffff0000           
    add $t2, $s3, $s4            # $t2 = 0xffffffff

    # 0xffffffff+0xffffffff=0xfffffffe 负+负
    add $t3, $t2, $t2            # $t3 = 0xfffffffe

#ADDI
    # 一般情况 正+正
    addi $t7, $s0, 0x0fff        # $t7 = 0x00011085

    # 0x000f0f0f+0xfffff0f1=0x000f0000 进位
    li $s6, 0x000f0f0f             
    addi $t8, $s6, 0xf0f1        # $t8 = 0x000f0000

    # 0xffffffff+0xfffff0f1=0xfffff0f0 负+负
    addi $t9, $t2, 0xf0f1        # $t9 = 0xfffff0f0

    # 0x000f000f+0x00000fff=0x000f100e 正+负
    addi $a0, $s2, 0x0fff        # $a0 = 0x000f100e

#ADDU 无例外
    # 一般情况 正+正                 
    add $a1, $s0, $s1            # $a1 = 0x00020077

    # 0x000f000f+0x0000fff1=0x00100000 进位                     
    add $a2, $s1, $s2            # $a2 = 0x00100000

    # 0x0000ffff+0xffff0000=0xffffffff 正+负          
    add $a3, $s3, $s4            # $a3 = 0xffffffff

    # 0xffffffff+0xffffffff=0xfffffffe 负+负
    add $v0, $t2, $t2            # $v0 = 0xfffffffe

#ADDIU 无例外
    # 一般情况 正+正
    addi $gp, $s0, 0x0fff        # $gp = 0x00011085

    # 0x000f0f0f+0xfffff0f1=0x000f0000 进位           
    addi $sp, $s6, 0xf0f1        # $sp = 0x000f0000

    # 0xffffffff+0xfffff0f1=0xfffff0f0 负+负
    addi $fp, $t2, 0xf0f1        # $fp = 0xfffff0f0

    # 0x000f000f+0x00000fff=0x000f100e 正+负
    addi $s7, $s2, 0x0fff        # $s7 = 0x000f100e

#ADD 例外
    # 0x80000000+0xffffffff=0x7fffffff 负溢出
    li $s5, 0x80000000
    add $t4, $s5, $t2            # $t4 = 0x7fffffff

    # 0x7fffffff+0x00000001=0x80000000 正溢出
    li $k0, 0x1
    li $t4, 0x7fffffff
    add $t5, $t4, $k0            # $t5 = 0x80000000

#ADDI 例外
    # 0x80000000+0xffffffff=0x7fffffff 负溢出
    li $t5, 0x80000000
    addi $t6, $t5, 0xffff    # $t6 = 0x7fffffff

    # 0x7fffffff+0x00000001=0x80000000 正溢出
    li $t6, 0x7fffffff
    addi $v1, $t6, 0x1           # $v1 = 0x80000000
   
   HIT_GOOD_TRAP		#stop temu


    .org 0x380
        nop
        mfc0 $k0, $13, 0x0

        andi $k0, $k0, 0x00000ff
        srl $k0, $k0, 0x2

        li $k1, 0x0c
        beq $k0, $k1, OVERFLOW
        HIT_BAD_TRAP

        OVERFLOW:
            ERET    